import { getApiResolveRegionsListApi } from '@/apis/modules/resolve/area'
import type { CloudFilterBarScheme } from '@/components/filter-bar/types'
import { Tooltip } from '@arco-design/web-vue'
import IconsQuestion from '~icons/icons/question'
export default function useTableColumn() {
  const columns = buildColumns([
    {
      title: '节点名称',
      dataIndex: 'name',
      width: 194,
      slotName: 'name'
      // render({ record }) {
      //   return record.name
      // }
      // title: '节点名称',
      //   dataIndex: 'name',
      //   cellClass: 'link ',
      //   width: 200,
      //   slotName: 'domain',
      //   format: 'copy',
      //   clickFn: (row) => {
      //     useSiteStore().setSiteInfo(row)
      //     router.push({
      //       name: 'SiteConfig',
      //       params: { id: row.id }
      //     })
      //   }
    },
    {
      title: 'IP',
      dataIndex: 'ip',
      width: 194,
      slotName: 'ip'
    },
    {
      title: '所属区域',
      width: 194,
      render({ record }) {
        return record.region_info.name
      }
    },
    {
      width: 120,
      title: () => (
        <div class="flex gap-x-1 items-center ">
          <span class="text-sm/22px">节点层级</span>
          <Tooltip>
            {{
              default: () => <IconsQuestion class="question-icon" />,
              content: () => (
                <span>
                  1. L2 节点负责回源，L1 节点自动从 L2 节点获取源站数据；
                  <br />
                  2. 如果没有 L2 节点，L1 节点直接向源站请求回源。
                </span>
              )
            }}
          </Tooltip>
        </div>
      ),
      render({ record }) {
        return record.cascade_level === 1 ? 'L1' : 'L2'
      }
    },
    {
      title: '运行状态',
      width: 194,
      dataIndex: 'status',
      slotName: 'status'
    },
    {
      title: '解析状态',
      width: 194,
      dataIndex: 'resolve_status',
      slotName: 'resolve_status'
    },
    {
      title: '程序版本',
      width: 194,
      dataIndex: 'version',
      slotName: 'version'
    },
    {
      title: '操作系统',
      width: 194,
      slotName: 'os'
    },
    {
      title: '操作',
      slotName: 'action',
      width: 120,
      cellClass: 'actions-cell'
    }
  ])
  const filterScheme: CloudFilterBarScheme = {
    widgets: [
      {
        widget: 'select',
        field: 'region_id',
        allText: '全部区域',
        fieldNames: {
          label: 'name',
          value: 'id'
        },
        fn: getApiResolveRegionsListApi
      },
      {
        widget: 'select',
        field: 'status',
        allText: '全部运行状态',
        options: nodeStatusOptions
      },
      {
        widget: 'strong-search',
        placeholder: '默认按照节点主 IP 搜索',
        options: [
          {
            label: '节点主 IP',
            field: 'primary_ip',
            maxLength: 30
          },
          {
            label: '节点名称',
            field: 'name'
          }
        ]
      }
    ]
  }
  return { columns, filterScheme }
}
